package com.cangxuan.backend.controller;

import com.cangxuan.backend.annotation.Check;
import com.cangxuan.backend.annotation.check.NotNull;
import com.cangxuan.backend.service.IOrderFormService;
import io.swagger.annotations.*;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Author: 陈青石
 * 订单接口
 */
@Api(tags = "订单相关接口")
@RestController
@RequestMapping("orderform")
public class OrderFormController extends BaseController {

    IOrderFormService orderFormService;

    @Autowired
    public void setOrderFormService(IOrderFormService orderFormService) {
        this.orderFormService = orderFormService;
    }

    @Data
    @ApiModel("购买藏品信息")
    public static class PayParam{
        @ApiModelProperty("藏品ID")
        @NotNull(message = "请传递goodsId")
        Integer goodsId;

        @ApiModelProperty("购买藏品数量")
        @NotNull(message = "请传递count")
        Integer count;
    }

    @PostMapping("creatOrderForm")
    @ApiOperation("【需要登录】一级市场藏品创建订单")
    public Object creatOrderForm(@ApiParam("购买藏品信息") @Check @RequestBody PayParam payParam) {

        return success("订单创建成功", orderFormService.creatOrderForm(payParam.getGoodsId(),payParam.getCount()));
    }

    @GetMapping("successPay/{orderId}")
    @ApiOperation("【需要登录】成功支付修改订单")
    public Object successPay(@ApiParam("修改订单Id") @PathVariable int orderId) {
        int res = orderFormService.successPay(orderId);
        return success("成功支付到"+res+"件藏品");
    }

    @GetMapping("cancel/{orderId}")
    @ApiOperation("【需要登录】取消订单")
    public Object cancelOderForm(@ApiParam("取消订单Id") @PathVariable int orderId) {
        orderFormService.cancelOderForm(orderId);
        return success("取消成功");
    }

    @GetMapping("get/{comeFrom}/{state}")
    @ApiOperation("【需要登录】获取订单")
    public Object getOderForm(@ApiParam("获取订单来源0藏品订单、1市场订单") @PathVariable int comeFrom,@ApiParam("获取订单状态1待支付、2已完成、3已取消") @PathVariable int state) {

        return success("获取成功",orderFormService.getOderForm(comeFrom,state));
    }


    @GetMapping("overTime/{orderId}")
    @ApiOperation("【需要登录】尝试判断订单是否超时")
    public Object orderFormOverTime(@ApiParam("取消订单Id") @PathVariable int orderId) {
        orderFormService.tryCancelOverTime(orderId);
        return success("没有超时");
    }



}
